<?php
  session_start();
?>

<!DOCTYPE html>
<html lang="en">
<head>
        <title>CoBAGSys - Home</title>
        <link type="text/css" rel="stylesheet" href="css/mystyle.css">
</head>
<body>
    <?php
      require 'menus.php';
      require 'gChart.php';
    ?>
    <?php
    	
    	// Returns the name of a given category in the database
    	function getCategoryName($cid) {
			$db = new Connect();

			$sql = "SELECT cName FROM Category WHERE cid = '" . $cid . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return "";
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows[0]['cName'];
			}
    	}
    	
    	// Returns a list of postings in a given category
    	function getPostingsInCategory($cName) {
			$db = new Connect();
			
			$sql = "SELECT p.pID as PostingID, IFNULL(p.pCity, m.mCity) as City, m.mName as PostedBy, p.pName as Item, " . 
						"p.pDesc as Description, p.price as Price, p.pDatetime as Date, p.status as Status " . 
					"FROM MemberInfo m JOIN Posting p on m.mID = p.mID JOIN Category c ON p.cID = c.cID " . 
					"WHERE c.cName = '" . $cName . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of members from the given city
    	function getMembersFromCity($city) {
			$db = new Connect();
			
			$sql = "SELECT m.mID as MemberID, m.mName as Name, m.admin as IsAdmin, m.suspended as IsSuspended " . 
					"FROM MemberInfo m WHERE m.mCity = '" . $city . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of members with postings in the given category
    	function getMembersWithPostingsInCategory($cName) {
			$db = new Connect();
			
			$sql = "SELECT DISTINCT m.mID as MemberID, m.mName as Name, m.mCity as City, m.admin as IsAdmin, m.suspended as IsSuspended " . 
					"FROM MemberInfo m JOIN Posting p ON m.mID = p.mID JOIN Category c ON c.cID = p.cID WHERE cName = '" . $cName . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of transactions made by a given member
    	function getTransactionsMadeByMember($mName) {
			$db = new Connect();
			
			$sql = "SELECT t.tID as TransactionID, t.pID as PostingID, t.tDatetime as Date, t.tDesc as Description, t.price as Price, " .
						"t.revenue as Revenue, t.final as IsFinal, IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) as City  " .  
					"FROM Transaction t JOIN Posting p on t.pID = p.pID JOIN MemberInfo m on p.mID = m.mID WHERE m.mName = '" . $mName . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of the highest rated members
    	function getHighestRatedMembers() {
			$db = new Connect();
			
			$sql = "SELECT mID as MemberID, mName as Name, rating as AverageRating " . 
					"FROM AverageRatings GROUP BY rating DESC";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of the lowest rated members
    	function getLowestRatedMembers() {
			$db = new Connect();
			
			$sql = "SELECT mID as MemberID, mName as Name, rating as AverageRating " . 
					"FROM AverageRatings GROUP BY rating";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of member stats by category
    	function getMemberStatsByCategory($cName) {
			$db = new Connect();
			
			$sql = "SELECT r.mID as MemberID, r.mName as Name, r.rating as AverageRating " . 
					"FROM AverageRatings r JOIN Posting p ON r.mID = p.mID JOIN Category c ON c.cID = p.cID " . 
					"WHERE c.cName = '" . $cName . "' GROUP BY r.mID ORDER BY r.rating DESC";
					
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of transaction stats in time period
    	function getTransactionStatsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT t.tID as TransactionID, t.pID as PostingID, t.tDatetime as Date, t.tDesc as Description, t.price as Price, " .
						"t.revenue as Revenue, t.final as IsFinal, IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) as City  " .  
					"FROM Transaction t JOIN Posting p on t.pID = p.pID JOIN MemberInfo m on p.mID = m.mID " . 
					"WHERE tDatetime >= '" . $startDatetime . "' AND tDatetime <= '" . $endDatetime . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of income for the given status
    	function getIncomeFromStatus($status) {
			$db = new Connect();
			
			$sql = "SELECT i.tID as TransactionID, i.revenue as Revenue, i.status as Status " . 
					"FROM IncomeActivities i WHERE i.status = '" . $status . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of postings made within the given time period
    	function getPostingsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT p.pID as PostingID, IFNULL(p.pCity, m.mCity) as City, m.mName as PostedBy, p.pName as Item, " . 
						"p.pDesc as Description, p.price as Price, p.pDatetime as Date, p.status as Status " . 
					"FROM Posting p JOIN MemberInfo m on p.mID = m.mID " . 
					"WHERE pDatetime >= '" . $startDatetime . "' AND pDatetime <= '" . $endDatetime . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of postings made by the given member
    	function getPostingsByMember($mName) {
			$db = new Connect();
			
			$sql = "SELECT p.pID as PostingID, IFNULL(p.pCity, m.mCity) as City, m.mName as PostedBy, p.pName as Item, " . 
						"p.pDesc as Description, p.price as Price, p.pDatetime as Date, p.status as Status " . 
					"FROM Posting p JOIN MemberInfo m ON m.mID = p.pID WHERE m.mName = '" . $mName . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of charges made on a member's credit card
    	function getChargesOnMemberCreditCard($mName) {
			$db = new Connect();
			
			$sql = "SELECT DISTINCT t.tID as TransactionID, t.pID as PostingID, t.tDatetime as Date, t.tDesc as Description, t.price as Price, " .
						"t.revenue as Revenue, t.final as IsFinal, IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) as City  " .  
					"FROM MemberInfo m JOIN Posting p on m.mID = p.mID JOIN Transaction t ON t.email = m.email " . 
					"WHERE t.final = TRUE AND m.mName = '" . $mName . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of members with the most transactions in the given time period
    	function getMembersWithMostTransactionsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT m.mID as MemberID, m.mName as Name, COUNT(*) as NumberOfTransactions " . 
					"FROM Transaction t JOIN Posting p on t.pID = p.pID JOIN MemberInfo m on t.email = m.email " . 
					"WHERE t.tDatetime >= '" . $startDatetime . "' " . 
					"AND t.tDatetime <= '" . $endDatetime . "' " . 
					"GROUP BY m.mID " . 
					"ORDER BY COUNT(*) DESC";
					
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of cities with the most transactions in the given time period
    	function getCitiesWithMostTransactionsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) as City, COUNT(*) as NumberOfTransactions " . 
					"FROM Transaction t JOIN Posting p on t.pID = p.pID JOIN MemberInfo m on t.email = m.email " . 
					"WHERE t.tDatetime >= '" . $startDatetime . "' " . 
					"AND t.tDatetime <= '" . $endDatetime . "' " . 
					"GROUP BY City " . 
					"ORDER BY COUNT(*) DESC";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of provinces with the most transactions in the given time period
    	function getProvincesWithMostTransactionsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT l.province as Province, COUNT(*) as NumberOfTransactions " . 
					"FROM Transaction t JOIN Posting p on t.pID = p.pID JOIN MemberInfo m on t.email = m.email " . 
						"JOIN Location l on l.city = IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) " . 
					"WHERE t.tDatetime >= '" . $startDatetime . "' " . 
					"AND t.tDatetime <= '" . $endDatetime . "' " . 
					"GROUP BY l.province " . 
					"ORDER BY COUNT(*) DESC";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of countries with the most transactions in the given time period
    	function getCountriesWithMostTransactionsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT l.country as Country, COUNT(*) as NumberOfTransactions " . 
					"FROM Transaction t JOIN Posting p on t.pID = p.pID JOIN MemberInfo m on t.email = m.email " . 
						"JOIN Location l on l.city = IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) " . 
					"WHERE t.tDatetime >= '" . $startDatetime . "' " . 
					"AND t.tDatetime <= '" . $endDatetime . "' " . 
					"GROUP BY l.country " . 
					"ORDER BY COUNT(*) DESC";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of transactions made in a given category
    	function getTransactionsInCategory($cName) {
			$db = new Connect();
			
			$sql = "SELECT t.tID as TransactionID, m.mName as MadeBy, t.pID as PostingID, t.tDatetime as Date, t.tDesc as Description, " .
						"t.price as Price, t.revenue as Revenue, t.final as IsFinal, IFNULL(t.tCity, IFNULL(p.pCity, m.mCity)) as City  " .  
					"FROM Transaction t JOIN Posting p ON t.pID = p.pID JOIN MemberInfo m on t.email = m.email " . 
						"JOIN Category c ON c.cID = p.cID " . 
					"WHERE c.cName = '" . $cName . "'";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of transactions made from a different location than the posting location in a given time period
    	function getTransactionsBetweenDifferentLocationsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT t.tID as TransactionID, t.tCity as TransactionCity, IFNULL(p.pCity, m.mCity) as PostingCity, " . 
						"m.mName as MadeBy, t.pID as PostingID, t.tDatetime as Date, t.tDesc as Description, " .
						"t.price as Price, t.revenue as Revenue, t.final as IsFinal " .  
					"FROM Posting p JOIN Transaction t ON p.pID = t.pID JOIN MemberInfo m ON t.email = m.email " . 
					"WHERE t.tCity <> IFNULL(p.pCity, m.mCity) " . 
					"AND tDatetime >= '" . $startDatetime . "' " . 
					"AND tDatetime <= '" . $endDatetime . "' ";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of transactions made from the given location on postings from the given location in a given time period
    	function getTransactionsBetweenSpecifiedLocationsInTimePeriod($tCity, $pCity, $startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT t.*, IFNULL(p.pCity, m.mCity) as city " . 
					"FROM Posting p JOIN Transaction t ON p.pID = t.pID JOIN MemberInfo m ON m.mID = p.pID " . 
					"WHERE t.tCity = '" . $tCity . "' " . 
					"AND city = '" . $pCity . "' " . 
					"AND tDatetime >= '" . $startDatetime . "' " . 
					"AND tDatetime <= '" . $endDatetime . "' ";
			
			$sql = "SELECT t.tID as TransactionID, m.mName as MadeBy, t.pID as PostingID, t.tDatetime as Date, t.tDesc as Description, " .
						"t.price as Price, t.revenue as Revenue, t.final as IsFinal " .  
					"FROM Posting p JOIN Transaction t ON p.pID = t.pID JOIN MemberInfo m ON t.email = m.email " . 
					"WHERE t.tCity = '" . $tCity . "' " . 
					"AND IFNULL(p.pCity, m.mCity) = '" . $pCity . "' " . 
					"AND tDatetime >= '" . $startDatetime . "' " . 
					"AND tDatetime <= '" . $endDatetime . "' ";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of members who made at least one transaction in the given time period
    	function getMembersWithTransactionsInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT m.mID as MemberID, m.mName as Name " . 
					"FROM MemberInfo m JOIN Transaction t ON m.email = t.email " . 
					"WHERE tDatetime >= '" . $startDatetime . "' " . 
					"AND tDatetime <= '" . $endDatetime . "' " . 
					"GROUP BY m.mID";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of members who made at least one transaction in the given category in the given time period
    	function getMembersWithTransactionsInCategoryInTimePeriod($cName, $startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT m.mID as MemberID, m.mName as Name, COUNT(*) as NumberOfTransactions " . 
					"FROM Posting p JOIN Transaction t ON p.pID = t.pID JOIN MemberInfo m ON t.email = m.email JOIN Category c on c.cID = p.cID " . 
					"WHERE c.cName = '" . $cName . "' " . 
					"AND t.tDatetime >= '" . $startDatetime . "' " . 
					"AND t.tDatetime <= '" . $endDatetime . "' " . 
					"GROUP BY m.mID " . 
					"ORDER BY COUNT(*) DESC";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    	
    	// Returns a list of members with the largest number of transactions in the smallest number of categories in the given time period
    	function getMembersWithMostTransactionsInLeastCategoriesInTimePeriod($startDatetime, $endDatetime) {
			$db = new Connect();
			
			$sql = "SELECT mt.MemberID, mt.Name, mt.NumberOfTransactions, COUNT(*) as NumberOfCategories " . 
					"FROM (SELECT m.mID as MemberID, m.mName as Name, m.email as email, COUNT(*) as NumberOfTransactions " . 
									"FROM Posting p JOIN Transaction t ON p.pID = t.pID JOIN MemberInfo m ON t.email = m.email " . 
									"WHERE t.tDatetime >= '" . $startDatetime . "' " . 
									"AND t.tDatetime <= '" . $endDatetime . "' " . 
									"GROUP BY m.mID " . 
									"ORDER BY COUNT(*) DESC) as mt " . 
					"JOIN Transaction t ON t.email = mt.email JOIN Posting p ON p.pID = t.pID " . 
					"GROUP BY p.cID";
			
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
				$rows = $db->to_array($result);
				return $rows;
			}
    	}
    
    	// Displays the given table rows
    	function displayRows($rows, $title) {
			
	    	print $title . "";
			$rowcount = count($rows);
			if ($rowcount > 0)
			{
				print "<table border=\"1\">";
				print "<tr>";
				foreach($rows[0] as $key => $column)
					print "<th class=\"normal\">" . $key . "</th>";
				print "</tr>";
				for ($i = 0; $i < $rowcount; $i++)
				{
					print "<tr>";
					foreach($rows[$i] as $column)
						print "<td class=\"normal\">" . $column . "</td>";	
					print "</tr>";
				}
				print "</table>";
			}
    	}
    	
    	function initGraph($arrLabel,$arrData)
		{
			$pie3dChart1 = new gPie3DChart();
	                $pie3dChart1->addDataSet($arrData);
			$pie3dChart1->setLegend($arrLabel);
	                $pie3dChart1->setLabels($arrLabel);
			$pie3dChart1->setColors(array("ff3344", "11ff11", "22aacc", "3333aa","ffff33","66FFCC"));
			echo "<img src='" .  $pie3dChart1->getUrl() .  "' /> <br>";		
		}
    	
		function getHighestRatedMembersWithGraph()
		{
			$db = new Connect();
			
			//$sql = "SELECT mName, rating FROM AverageRatings HAVING rating >= ALL (SELECT rating FROM AverageRatings)";
			//echo $sql;
			$sql = "SELECT mName as Name, rating as AverageRating " . 
					"FROM AverageRatings GROUP BY rating DESC";
			$result = $db->query($sql);
			//echo $result;
			if(!$result || mysql_num_rows($result) == 0)
                        {
                                return "";
                        }
            else
                        {
                                
                                //return $rows[0]['cName'];
						$arrData = array();
		                $arrLabel  = array();
	
		                $rows = $db->to_array($result);
		                
						foreach($rows as $row)
	                    {
        	                        array_push($arrLabel, $row['Name']);
                	                array_push($arrData, $row['AverageRating']);
                        }
                        
                        
                        //return array($arrLabel,$arrData);
						initGraph($arrLabel,$arrData);
						/*
						$pie3dChart1 = new gPie3DChart();
	       				$pie3dChart1->addDataSet($arrData);
						$pie3dChart1->setLegend($arrLabel);
	        			$pie3dChart1->setLabels($arrLabel);
						$pie3dChart1->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
						
						echo "<img src='" .  $pie3dChart1->getUrl() .  "' /> <br>";
                        */
						}
			
		}
		
		function getLowestRatedMembersWithGraph()
		{
			$db = new Connect();
			
			//$sql = "SELECT mName, rating FROM AverageRatings HAVING rating <= ALL (SELECT rating FROM AverageRatings)";
			//echo $sql;
			$sql = "SELECT mName as Name, rating as AverageRating " . 
					"FROM AverageRatings GROUP BY rating";
			$result = $db->query($sql);
			//echo $result;
			if(!$result || mysql_num_rows($result) == 0)
            {
                                return "";
            }
            else
            {
                                
                                //return $rows[0]['cName'];
						$arrData = array();
		                $arrLabel  = array();
	
		                $rows = $db->to_array($result);
		                
						foreach($rows as $row)
	                    {
       	                        array_push($arrLabel, $row['Name']);
               	                array_push($arrData, $row['AverageRating']);
                      	}
                        //return array($arrLabel,$arrData);
						
                        initGraph($arrLabel,$arrData);
						/*
                        $pie3dChart2 = new gPie3DChart();
	       				$pie3dChart2->addDataSet($arrData);
						$pie3dChart2->setLegend($arrLabel);
	        			$pie3dChart2->setLabels($arrLabel);
						$pie3dChart2->setColors(array("ff3344", "11ff11", "22aacc", "3333aa"));
						
						echo "<img src='" .  $pie3dChart2->getUrl() .  "' /> <br>";
                        */
						}
			
		}
		
	   	function getMemberStatsByCategoryWithGraph($cName) {
			$db = new Connect();
			
			$sql = "SELECT r.mID as MemberID, r.mName as Name, r.rating as AverageRating " . "FROM AverageRatings r JOIN Posting p ON r.mID = 
p.mID JOIN Category c ON c.cID = p.cID " . 
					"WHERE c.cName = '" . $cName . "' 
GROUP BY r.mID ORDER BY r.rating DESC";
					
			$result = $db->query($sql);
			
			if(!$result || mysql_num_rows($result) == 0)
			{
				return;
			}
			else
			{
						$arrData = array();
		                $arrLabel  = array();
	
		                $rows = $db->to_array($result);
		                
						foreach($rows as $row)
	                    {
       	                        array_push($arrLabel, $row['Name']);
               	                array_push($arrData, 
$row['AverageRating']);
                      	}
                        //return array($arrLabel,$arrData);
						
                        initGraph($arrLabel,$arrData);
			}
    	}
    ?>
    <div id="reports">
      	<p class="title">
      		Reports
      	</p>
      	<?php
    	
	    	if (isset($_POST['getHighestRatedMembers']))
	    	{
	    		displayRows(getHighestRatedMembers(), 'Highest Rated Members');
    		}
	    	if (isset($_POST['getHighestRatedMembersWithGraph']))
	    	{
		    	getHighestRatedMembersWithGraph();
		    }	
	   
	    	if (isset($_POST['getLowestRatedMembers']))
	    	{
	    		displayRows(getLowestRatedMembers(), 'Lowest Rated Members');
    		}
	    	if (isset($_POST['getLowestRatedMembersWithGraph']))
	    	{
		    	getLowestRatedMembersWithGraph();
		    }	
	    	
	    	if (isset($_POST['getPostingsInCategory']))
	    		displayRows(getPostingsInCategory($_POST['category']), 'Postings in ' . $_POST['category']);
	    	
	    	if (isset($_POST['getTransactionsInCategory']))
	    		displayRows(getTransactionsInCategory($_POST['category']), 'Transactions in ' . $_POST['category']);
	    	
	    	if (isset($_POST['getMembersWithPostingsInCategory']))
	    		displayRows(getMembersWithPostingsInCategory($_POST['category']), 'Members with Postings in ' . $_POST['category']);
	    	
	    	if (isset($_POST['getMemberStatsByCategory']))
	    		displayRows(getMemberStatsByCategory($_POST['category']), 'Member Stats by ' . $_POST['category']);
	    	
		if (isset($_POST['getMemberStatsByCategoryWithGraph']))
	    	{
	    		getMemberStatsByCategoryWithGraph($_POST['category']);
	    	}

	    	if (isset($_POST['getMembersFromCity']))
	    		displayRows(getMembersFromCity($_POST['city']), 'Members from ' . $_POST['city']);
	    	
	    	if (isset($_POST['getPostingsByMember']))
	    		displayRows(getPostingsByMember($_POST['member']), 'Postings by ' . $_POST['member']);
	    	
	    	if (isset($_POST['getTransactionsMadeByMember']))
	    		displayRows(getTransactionsMadeByMember($_POST['member']), 'Transactions Made by ' . $_POST['member']);
	    	
	    	if (isset($_POST['getChargesOnMemberCreditCard']))
	    		displayRows(getChargesOnMemberCreditCard($_POST['member']), 'Charges on ' . $_POST['member'] . '\'s Credit Card');
	    	
	    	if (isset($_POST['getIncomeFromStatus']))
	    		displayRows(getIncomeFromStatus($_POST['status']), 'Income from ' . $_POST['status']);
	    	
	    	if (isset($_POST['getPostingsInTimePeriod']))
	    		displayRows(getPostingsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Postings from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getTransactionStatsInTimePeriod']))
	    		displayRows(getTransactionStatsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Transactions from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getMembersWithTransactionsInTimePeriod']))
	    		displayRows(getMembersWithTransactionsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Members with Transactions from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getMembersWithMostTransactionsInTimePeriod']))
	    		displayRows(getMembersWithMostTransactionsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Members with Most Transactions from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getCitiesWithMostTransactionsInTimePeriod']))
	    		displayRows(getCitiesWithMostTransactionsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Cities with Most Transactions from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getProvincesWithMostTransactionsInTimePeriod']))
	    		displayRows(getProvincesWithMostTransactionsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Provinces with Most Transactions from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getCountriesWithMostTransactionsInTimePeriod']))
	    		displayRows(getCountriesWithMostTransactionsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Countries with Most Transactions from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getMembersWithMostTransactionsInLeastCategoriesInTimePeriod']))
	    		displayRows(getMembersWithMostTransactionsInLeastCategoriesInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Members with Most Transactions in Least Categories from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getTransactionsBetweenDifferentLocationsInTimePeriod']))
	    		displayRows(getTransactionsBetweenDifferentLocationsInTimePeriod($_POST['startDatetime'], $_POST['endDatetime']), 'Transactions Between Different Locations from ' . $_POST['startDatetime'] . ' to ' . $_POST['endDatetime']);
	    	
	    	if (isset($_POST['getTransactionsBetweenSpecifiedLocationsInTimePeriod']))
	    		displayRows(getTransactionsBetweenSpecifiedLocationsInTimePeriod($_POST['tCity'], $_POST['pCity'], $_POST['startDatetime2'], $_POST['endDatetime2']), 'Transactions in ' . $_POST['tCity'] . ' on Postings in ' . $_POST['pCity'] . ' from ' . $_POST['startDatetime2'] . ' to ' . $_POST['endDatetime2']);
	    	
	    	if (isset($_POST['getMembersWithTransactionsInCategoryInTimePeriod']))
	    		displayRows(getMembersWithTransactionsInCategoryInTimePeriod($_POST['category2'], $_POST['startDatetime3'], $_POST['endDatetime3']), 'Members with Transactions in ' . $_POST['category2'] . ' from ' . $_POST['startDatetime3'] . ' to ' . $_POST['endDatetime3']);
	
      	?>
      	<form id="reportsForm" action="" method="post">
      	<br>
		<br>
		<input type="submit" class="smallButton" value="Highest rated members" name="getHighestRatedMembers"/>
		<input type="submit" class="smallButton" value="graph" name="getHighestRatedMembersWithGraph"/>
		<br>
		<input type="submit" class="smallButton" value="Lowest rated members" name="getLowestRatedMembers"/>
		<input type="submit" class="smallButton" value="graph" name="getLowestRatedMembersWithGraph"/>
		<br>
		<br>
		<?php
		if (isset($_POST['category']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"category\" placeholder=\"category name\" value=\"" . $_POST['category'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"category\" placeholder=\"category name\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Postings in category" name="getPostingsInCategory"/>
		<br>
		<input type="submit" class="smallButton" value="Transactions in category" name="getTransactionsInCategory"/>
		<br>
		<input type="submit" class="smallButton" value="Members with postings in category" name="getMembersWithPostingsInCategory"/>
		<br>
		<input type="submit" class="smallButton" value="Member stats by category" name="getMemberStatsByCategory"/>
		<input type="submit" class="smallButton" value="graph" name="getMemberStatsByCategoryWithGraph"/>
		<br>
		<br>
		<?php
		if (isset($_POST['city']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"city\" placeholder=\"city\" value=\"" . $_POST['city'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"city\" placeholder=\"city\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Members from city" name="getMembersFromCity"/>
		<br>
		<br>
		<?php
		if (isset($_POST['member']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"member\" placeholder=\"member name\" value=\"" . $_POST['member'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"member\" placeholder=\"member name\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Postings by member" name="getPostingsByMember"/>
		<br>
		<input type="submit" class="smallButton" value="Transactions made by member" name="getTransactionsMadeByMember"/>
		<br>
		<input type="submit" class="smallButton" value="Charges on member credit card" name="getChargesOnMemberCreditCard"/>
		<br>
		<br>
		<?php
		if (isset($_POST['status']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"status\" placeholder=\"status\" value=\"" . $_POST['status'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"status\" placeholder=\"status\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Income from status" name="getIncomeFromStatus"/>
		<br>
		<br>
		<?php
		if (isset($_POST['startDatetime']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"startDatetime\" placeholder=\"start date/time\" value=\"" . $_POST['startDatetime'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"startDatetime\" placeholder=\"start date/time\">";
		?>
		<?php
		if (isset($_POST['endDatetime']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"endDatetime\" placeholder=\"end date/time\" value=\"" . $_POST['endDatetime'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"endDatetime\" placeholder=\"end date/time\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Postings in time period" name="getPostingsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Transaction stats in time period" name="getTransactionStatsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Members with transactions in time period" name="getMembersWithTransactionsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Members with most transactions in time period" name="getMembersWithMostTransactionsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Cities with most transactions in time period" name="getCitiesWithMostTransactionsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Provinces with most transactions in time period" name="getProvincesWithMostTransactionsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Countries with most transactions in time period" name="getCountriesWithMostTransactionsInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Members with most transactions in least categories in time period" name="getMembersWithMostTransactionsInLeastCategoriesInTimePeriod"/>
		<br>
		<input type="submit" class="smallButton" value="Transactions between different locations in time period" name="getTransactionsBetweenDifferentLocationsInTimePeriod"/>
		<br>
		<br>
		<?php
		if (isset($_POST['tCity']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"tCity\" placeholder=\"transaction city\" value=\"" . $_POST['tCity'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"tCity\" placeholder=\"transaction city\">";
		?>
		<?php
		if (isset($_POST['pCity']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"pCity\" placeholder=\"posting city\" value=\"" . $_POST['pCity'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"pCity\" placeholder=\"posting city\">";
		?>
		<br>
		<?php
		if (isset($_POST['startDatetime2']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"startDatetime2\" placeholder=\"start date/time\" value=\"" . $_POST['startDatetime2'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"startDatetime2\" placeholder=\"start date/time\">";
		?>
		<?php
		if (isset($_POST['endDatetime2']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"endDatetime2\" placeholder=\"end date/time\" value=\"" . $_POST['endDatetime2'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"endDatetime2\" placeholder=\"end date/time\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Transactions between specified locations in time period" name="getTransactionsBetweenSpecifiedLocationsInTimePeriod"/>
		<br>
		<br>
		<?php
		if (isset($_POST['category2']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"category2\" placeholder=\"category name\" value=\"" . $_POST['category2'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"category2\" placeholder=\"category name\">";
		?>
		<br>
		<?php
		if (isset($_POST['startDatetime3']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"startDatetime3\" placeholder=\"start date/time\" value=\"" . $_POST['startDatetime3'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"startDatetime3\" placeholder=\"start date/time\">";
		?>
		<?php
		if (isset($_POST['endDatetime3']))
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"endDatetime3\" placeholder=\"end date/time\" value=\"" . $_POST['endDatetime3'] . "\">";
		else
			print "<input type=\"text\" maxlength=\"16\" size=\"16\" name=\"endDatetime3\" placeholder=\"end date/time\">";
		?>
		<br>
		<input type="submit" class="smallButton" value="Members with transactions in category in time period" name="getMembersWithTransactionsInCategoryInTimePeriod"/>
		<br>
		<br>
      	</form>
    </div>
</body>
</html>
